package com.kuang.controller;

import com.kuang.pojo.Location;
import com.kuang.service.DataCollectService;
import com.kuang.service.UsageService;
import com.kuang.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/location")
public class UsageController {
    //Controller调Service层
    @Autowired
    @Qualifier("UsageServiceImpl")
    private UsageService usageService;
    @Autowired
    @Qualifier("DataCollectServiceImpl")
    private DataCollectService dataCollectService;

    //查寻某个订单的 起始 终点 现在 位置
    @RequestMapping("/l1")
    public String text1(HttpServletResponse response,int usage_id) throws IOException {
        System.out.println("param==>"+usage_id);

        String begin = usageService.beginLocation(usage_id);
        System.out.println(begin);
        String arrival = usageService.arrivalLocation(usage_id);
        String location = dataCollectService.selectLocation(usage_id);

        List<String> list = new ArrayList<String>();
        list.add(begin);
        list.add(arrival);
        list.add(location);

        System.out.println(list);
        response.setContentType("text/javascript");
        response.getWriter().flush();
        response.getWriter().write(String.valueOf(list));
        response.getWriter().close();
        return JsonUtils.getJson(list);
    }

    //查询所有起始位置
    @RequestMapping("/l2")
    public String text2(HttpServletResponse response) throws IOException {
        List<Location> list = usageService.selectAllBegin_location();

        System.out.println(list);

        response.setContentType("text/javascript");
        response.getWriter().flush();
        response.getWriter().write(String.valueOf(list));
        response.getWriter().close();
        return JsonUtils.getJson(list);
    }

}
